package com.wao.product.service;

import com.wao.product.domain.Value;
import com.wao.product.repository.ValueRepository;
import com.wao.product.service.dto.ValueDTO;
import com.wao.product.service.mapper.ValueMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * Service Implementation for managing Value.
 */
@Service
@Transactional
public class ValueService {

    private final Logger log = LoggerFactory.getLogger(ValueService.class);

    private final ValueRepository valueRepository;

    private final ValueMapper valueMapper;

    public ValueService(ValueRepository valueRepository, ValueMapper valueMapper) {
        this.valueRepository = valueRepository;
        this.valueMapper = valueMapper;
    }

    /**
     * Save a value.
     *
     * @param valueDTO the entity to save
     * @return the persisted entity
     */
    public ValueDTO save(ValueDTO valueDTO) {
        log.debug("Request to save Value : {}", valueDTO);
        Value value = valueMapper.toEntity(valueDTO);
        value = valueRepository.save(value);
        return valueMapper.toDto(value);
    }

    /**
     *  Get all the values.
     *
     *  @param pageable the pagination information
     *  @return the list of entities
     */
    @Transactional(readOnly = true)
    public Page<ValueDTO> findAll(Pageable pageable) {
        log.debug("Request to get all Values");
        return valueRepository.findAll(pageable)
            .map(valueMapper::toDto);
    }

    /**
     *  Get one value by id.
     *
     *  @param id the id of the entity
     *  @return the entity
     */
    @Transactional(readOnly = true)
    public ValueDTO findOne(Long id) {
        log.debug("Request to get Value : {}", id);
        Value value = valueRepository.findOne(id);
        return valueMapper.toDto(value);
    }

    /**
     *  Delete the  value by id.
     *
     *  @param id the id of the entity
     */
    public void delete(Long id) {
        log.debug("Request to delete Value : {}", id);
        valueRepository.delete(id);
    }
}
